<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;

class Test extends Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    public function kaoqinremark()
    {
        $data = Db::table('kaoqin_remark')->where('kid','null')->field('id,img')->select()->toArray();
        $img = array_column($data,'img');
        $kaoqin = Db::table('kaoqin')->where('thumb','in',$img)->column('thumb,id');

        foreach ($data as $v){
            $kid = isset($kaoqin[$v['img']])?$kaoqin[$v['img']]:0;
            pr($kid);
            if($kid){
                Db::table('kaoqin_remark')->where('id','eq',$v['id'])->update(array('kid'=>$kid));
            }
        }
    }
    public function yuyue()
    {
        _pr(1);
        $list = Db::table('yuyue')->select();
        $fankui = Db::table('yuyue_fankui')->column('yid,mid');
        $manager = Db::table('manager')->column('id,email');
        foreach ($list as $k => $v) {
            if(isset($fankui[$v['id']])) {
                $save = [
                    'mid'=>$fankui[$v['id']],
                    'manager_name'=>$manager[$fankui[$v['id']]]
                ];
                Db::table('yuyue')->where('id',$v['id'])->update($save);
            }
        }
    }

    public function kaoqin()
    {
        _pr(1);
        //考勤表
//        $list = Db::table('zkhb_student_kaoqin')->field('*,count(thumb) as num')->group('thumb')->select()->toArray();
//        $save = [];
//        foreach ($list as $k=>$v){
//            $data = array(
//                'create_time' => $v['create_time'],
//                'update_time' => $v['update_time'],
//                'content' => $v['content'],
//                'manager_name' => $v['manager_name'],
//                'thumb' => $v['thumb'],
//                'time' => $v['time'],
//                'cid' => $v['cid'],
//                'num' => $v['num'],
//            );
//            $save[]=$data;
//        }
//        Db::table('kaoqin')->insertAll($save);

        //考勤学员表
        $kaoqin = Db::table('kaoqin')->limit(7366,500)->select();
        foreach ($kaoqin as $k=>$v){
            $w = array(
                'thumb'=>array('eq',$v['thumb'])
            );
            $kaoqinxueyuan = Db::table('zkhb_student_kaoqin')->where($w)->select()->toArray();
            if($kaoqinxueyuan){
                $save = [];
                foreach ($kaoqinxueyuan as $xv){
                    $xueyuan_data = array(
                        'create_time'=>$xv['create_time'],
                        'update_time'=>$xv['update_time'],
                        'sid'=>$xv['sid'],
                        'kid'=>$v['id']
                    );
                    $save[] = $xueyuan_data;
                }
                if ($save){
                    Db::table('kaoqin_xueyuan')->insertAll($save);
                }
            }
        }

    }

    public function test1()
    {
        _pr(1);
        $s = Db::table('xueyuan')->limit(300, 100)->select()->toArray();
        foreach ($s as $v){
            $w = array(
                'sid'=>$v['id'],
                'lose_time'=>array('>',time())
            );
            $id = Db::table('xueyuan_jiaofei')->where($w)->order('lose_time desc')->value('id');
            if(!$id){
                $id = Db::table('xueyuan_jiaofei')->where('sid',$v['id'])->order('lose_time desc')->value('id');
            }
            Db::table('xueyuan')->where('id',$v['id'])->update(['now_jid'=>$id]);
        }
    }

    public function test()
    {
        _pr(1);

        $s = Db::table('xueyuan')->limit(300, 100)->select()->toArray();
        foreach ($s as $st) {
           $new_data = Db::table('zkhb_student_copy1')->where('id','=',$st['id'])->find();
            $jiaofei = array(
                'sid' => $new_data['id'],
                'pay_money' => $new_data['pay_money'],
                'pay_time' => $new_data['pay_time'],
                'month' => $new_data['month'],
                'lose_time' => $new_data['lose_time'],
                'send_month' => $new_data['send_month'],
                'type' => $new_data['type'],
                'class_hour' => $new_data['class_hour'],
                'has_class_hour' => $new_data['has_class_hour'],
                'create_time' => $new_data['update_time'],
                'update_time' => $new_data['update_time']
            );

            Db::table('xueyuan_jiaofei')->insert($jiaofei);
//            $list = Db::table('loginfo')->where('data', 'like', '%:'.$st['id'].'%')->limit(0, 10)->select()->toArray();
//            $paytime = '';
//            foreach ($list as $k => $v) {
//                $list[$k]['new_data'] = json_decode($v['data'], true);
//                $new_data = json_decode($v['data'], true);
//                if($paytime != date('Y-m-d', $list[$k]['new_data']['pay_time'])){
//                    $jiaofei = array(
//                        'sid' => $new_data['id'],
//                        'pay_money' => $new_data['pay_money'],
//                        'pay_time' => $new_data['pay_time'],
//                        'month' => $new_data['month'],
//                        'lose_time' => $new_data['lose_time'],
//                        'send_month' => $new_data['send_month'],
//                        'type' => $new_data['type'],
//                        'class_hour' => $new_data['class_hour'],
//                        'has_class_hour' => $new_data['has_class_hour'],
//                        'create_time' => $new_data['update_time'],
//                        'update_time' => $new_data['update_time']
//                    );
//                    $paytime = date('Y-m-d', $list[$k]['new_data']['pay_time']);
//                    Db::table('xueyuan_jiaofei')->insert($jiaofei);
//                }
//
//            }
        }


//        _pr($list);
        }


    }
